#include<stdio.h>
#include<string.h>
void itob(int,char[],int);
void reverse(char []); 
int main()
{
  int n,b;
  char s[100];
  printf("enter a number");
  scanf("%d",&n);
  printf("enter the base for conversion");
  scanf("%d",&b);
  itob(n,s,b);
  printf("In base %d the number is ",b);
  puts(s);
  return 0;
}
void itob(int n,char s[],int b)
{
  int i=0;
  int ch;

  if(b==16)
  {
   while(n!=0)
   { 
     if((ch=n%b) >9)
       switch(ch)
        {        
         case 10:
                s[i++]='a';
                break;
         case 11:
                s[i++]='b';
                break;
         case 12:
                s[i++]='c';
                break;
         case 13:
                s[i++]='d';
                break;
         case 14:
                s[i++]='e';
                break;
         case 15:
                s[i++]='f';
                break;
        }
    else
      s[i++]=n%b +'0';
      n=n/b;
     }
   }    
     if(b!=16)
     while(n!=0)
       {
         s[i++]=n%b + '0';
         n=n/b;
       }
    s[i]='\0';
    reverse(s);
}   
void reverse(char s[])
{
  char ch;
  int i,j;
  for(i=0,j=strlen(s)-1;i<j;i++,j--)
    {
      ch=s[i];
      s[i]=s[j];
      s[j]=ch;
    }
} 
   


